package com.nix.web.service.word;

import com.nix.web.databases.jdbc.word.BatchAndTransactionToWord;
import com.nix.web.databases.mapper.word.WordMapper;
import com.nix.web.databases.pojo.word.Word;
import com.nix.web.databases.service.iteratory.Iterator;
import com.nix.web.databases.service.iteratory.ObjectAggregate;
import com.nix.web.databases.service.word.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Create by zhangpe0312@qq.com on 2017/12/21.
 */
@Service
public class WordServiceImpl extends WordService {

    @Autowired
    private WordMapper wordMapper;

    @Autowired
    private BatchAndTransactionToWord toWord;

    public void batchAddWord(ObjectAggregate aggregate, Integer groupNumber) {
        if (aggregate == null) {
            throw new NullPointerException("你给予的是一个空的迭代器！");
        }
        /**
         *  当集合的长度小于10000时，采用mybatis进行添加
         *  大于10000时，采用传统jdbc批量添加
         */
        if (aggregate.getLength() < 10000) {
            List<Word> list = aggregate.getList();
            wordMapper.addWordList(list);
        } else {
            toWord.bachAdd(aggregate.iterator(), groupNumber);
        }
    }

    @Override
    public void batchAddWord(Iterator iterator, Integer groupNumber) {
        toWord.bachAdd(iterator,groupNumber);
    }


    @Override
    public void addWordList(List<Word> words) {

    }

    @Override
    public void addCategory(Integer wid, Integer cid) {

    }

    @Override
    public List<Word> selectAll() {
        return wordMapper.selectAll();
    }
}
